<template>
    <div>
       
        <el-button 
            type="primary" 
            :icon="oneKeyDisabled ? 'el-icon-loading' : 'el-icon-jk-kuaijiejiancha'"
            @click="oneKeyCheck"
            :disabled="oneKeyDisabled">
            {{ this.oneKeyDisabled ? this.oneKeyDisabledNum + ' s' : '一键巡检' }}
        </el-button>
    </div>
</template>

<script>
import bus from 'common/bus';

export default {
    name: 'oneKey',
    data() {
        return {
            timerName: 'OneKey',
            timerEventName: 'timerOneKey',
            timerInterval: 1000 * 30,
            oneKeyDisabled: false,
            oneKeyDisabledNum: 9,
            timer: '',
			totalIntval: 3000,
			timerTodo: [
				{
					name: 'Warning',
					eventName: 'timerWarning',
					interval: 1000,
					intervalNow: 0,
				},
			],
        }
    },
    created() {
        bus.$on(this.timerEventName, msg => {
            if (msg.isGetData) {
                this.oneKeyDisabledNum -= 1;

                if (this.oneKeyDisabledNum <= 0) {
                    bus.$emit('timerNewTodo', {
                        name: this.timerName
                    });
                    this.oneKeyDisabled = false;
                    this.oneKeyDisabledNum = 9;
                }
            }
        });
     
    },
    methods: {
        oneKeyCheck() {
            this.oneKeyDisabled = true;
            
            

            bus.$emit('timerNewTodo', {
                name: this.timerName,
                eventName: this.timerEventName,
                interval: this.timerInterval,
                intervalNow: 0
            });
         
        }
    },
    beforeDestroy() {
        bus.$emit('timerNewTodo', {
            name: this.timerName
        });
    }
}
</script>

<style scoped>

</style>